package org.jsola.hr.helper;

import org.jsola.hr.dto.attendschedule.AttendStaffScheduleDTO;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class AttendStaffScheduleTestHelper extends BaseTestHelper {


    public List<AttendStaffScheduleDTO> getAttendStaffScheduleList() {

        List<AttendStaffScheduleDTO> list = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            AttendStaffScheduleDTO staff = new AttendStaffScheduleDTO();
            staff.setEmpInfoId(getRandomValue("varchar",32));
            staff.setEmpInfoName(getRandomValue("varchar",32));
            staff.setYearMonthDay(new SimpleDateFormat("yyyy-MM-dd").format(randomDate("2020-01-01","2020-02-02")));
            staff.setShiftName(getRandomValue("varchar",32));
            list.add(staff);
        }
        return list;
    }


    private static Date randomDate(String beginDate, String endDate){
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date start = format.parse(beginDate);
            Date end = format.parse(endDate);

            if(start.getTime() >= end.getTime()){
                return null;
            }
            long date = random(start.getTime(),end.getTime());
            return new Date(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static long random(long begin,long end){
        long rtn = begin + (long)(Math.random() * (end - begin));
        if(rtn == begin || rtn == end){
            return random(begin,end);
        }
        return rtn;
    }

}
